/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroDeProfessor.java
 *
 * Created on 12/11/2012, 15:53:23
 */
package distribuicaoDeProfessores;

/**
 *
 * @author Jaime
 */
public final class CadastroDeProfessor extends javax.swing.JPanel {
    Disciplinas disciplinas;
    JanelaPrincipal j;
    /** Creates new form CadastroDeProfessor */
    public CadastroDeProfessor(Disciplinas disciplinas, JanelaPrincipal j) {
        initComponents();
        this.j = j;
        professores = new Professores();
        this.disciplinas = disciplinas;
       // comboboxmodel(disciplinas);
    }

    public Professores getProfessores() {
        return professores;
    }

    public void setProfessores(Professores professores) {
        this.professores = professores;
    }
    
    public void comboboxmodel(Disciplinas disciplinas){
       try{ 
        if (disciplinas.disciplinas.isEmpty()) return;
        String[] nomes = new String[disciplinas.disciplinas.size()];
        for(int i = 0; i < disciplinas.disciplinas.size(); i++)
            nomes[i]= disciplinas.disciplinas.get(i).getNome();
    
        prioriade1D1.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade1D2.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade1D3.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade2D1.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade2D2.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade2D3.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade3D1.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade3D2.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        prioriade3D3.setModel(new javax.swing.DefaultComboBoxModel(nomes));
       }
       catch(NullPointerException NullPointerException){
          javax.swing.JOptionPane.showMessageDialog(null, "Bug ao carregar as disciplinas\nContacte o desenvolvedor", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
    }
    //@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        prioriade1D1 = new javax.swing.JComboBox();
        prioriade1D2 = new javax.swing.JComboBox();
        prioriade1D3 = new javax.swing.JComboBox();
        prioriade2D1 = new javax.swing.JComboBox();
        prioriade2D2 = new javax.swing.JComboBox();
        prioriade2D3 = new javax.swing.JComboBox();
        prioriade3D1 = new javax.swing.JComboBox();
        prioriade3D2 = new javax.swing.JComboBox();
        prioriade3D3 = new javax.swing.JComboBox();
        cadastrar = new javax.swing.JButton();

        setBackground(new java.awt.Color(153, 255, 153));
        setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setLayout(new java.awt.BorderLayout());

        jLabel1.setFont(new java.awt.Font("Script MT Bold", 1, 36));
        jLabel1.setForeground(new java.awt.Color(255, 51, 51));
        jLabel1.setText("Cadastro de Professor");
        add(jLabel1, java.awt.BorderLayout.PAGE_START);

        jPanel1.setBackground(new java.awt.Color(204, 255, 204));
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Nome:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Definir Preferencias:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Disciplinas de Prioridade 1 ");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Disciplinas de Prioridade 2 ");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Disciplinas de Prioridade 3");

        jTextField1.setColumns(50);
        jTextField1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        prioriade1D1.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade1D1.setMaximumRowCount(12);
        prioriade1D1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade1D1.setActionCommand("");
        prioriade1D1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade1D1.setEditor(null);
        prioriade1D1.setKeySelectionManager(null);

        prioriade1D2.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade1D2.setMaximumRowCount(12);
        prioriade1D2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade1D2.setActionCommand("");
        prioriade1D2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade1D2.setEditor(null);
        prioriade1D2.setKeySelectionManager(null);

        prioriade1D3.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade1D3.setMaximumRowCount(12);
        prioriade1D3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade1D3.setActionCommand("");
        prioriade1D3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade1D3.setEditor(null);
        prioriade1D3.setKeySelectionManager(null);

        prioriade2D1.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade2D1.setMaximumRowCount(12);
        prioriade2D1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade2D1.setActionCommand("");
        prioriade2D1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade2D1.setEditor(null);
        prioriade2D1.setKeySelectionManager(null);

        prioriade2D2.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade2D2.setMaximumRowCount(12);
        prioriade2D2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade2D2.setActionCommand("");
        prioriade2D2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade2D2.setEditor(null);
        prioriade2D2.setKeySelectionManager(null);

        prioriade2D3.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade2D3.setMaximumRowCount(12);
        prioriade2D3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade2D3.setActionCommand("");
        prioriade2D3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade2D3.setEditor(null);
        prioriade2D3.setKeySelectionManager(null);

        prioriade3D1.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade3D1.setMaximumRowCount(12);
        prioriade3D1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade3D1.setActionCommand("");
        prioriade3D1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade3D1.setEditor(null);
        prioriade3D1.setKeySelectionManager(null);

        prioriade3D2.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade3D2.setMaximumRowCount(12);
        prioriade3D2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade3D2.setActionCommand("");
        prioriade3D2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade3D2.setEditor(null);
        prioriade3D2.setKeySelectionManager(null);

        prioriade3D3.setFont(new java.awt.Font("Times New Roman", 0, 12));
        prioriade3D3.setMaximumRowCount(12);
        prioriade3D3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NULO" }));
        prioriade3D3.setActionCommand("");
        prioriade3D3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        prioriade3D3.setEditor(null);
        prioriade3D3.setKeySelectionManager(null);

        cadastrar.setBackground(new java.awt.Color(0, 204, 102));
        cadastrar.setFont(new java.awt.Font("Times New Roman", 1, 14));
        cadastrar.setForeground(new java.awt.Color(255, 51, 51));
        cadastrar.setText("Cadastrar");
        cadastrar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                        .addGap(295, 295, 295))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel3))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(45, 45, 45)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(prioriade1D2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(120, 120, 120))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(prioriade1D1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(120, 120, 120))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(prioriade1D3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(120, 120, 120))
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))))
                        .addGap(34, 34, 34)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(prioriade2D2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(120, 120, 120))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(prioriade2D1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(120, 120, 120))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(prioriade2D3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(120, 120, 120)))
                        .addGap(40, 40, 40)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(prioriade3D2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(120, 120, 120))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(prioriade3D1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(120, 120, 120))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(prioriade3D3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(120, 120, 120))
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))))
                .addGap(27, 27, 27))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(489, 489, 489)
                .addComponent(cadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(121, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(60, 60, 60)
                                .addComponent(jLabel5))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(jLabel6)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(prioriade2D1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prioriade2D2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prioriade2D3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(prioriade3D1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prioriade3D2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prioriade3D3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(prioriade1D1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prioriade1D2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prioriade1D3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(77, 77, 77)
                .addComponent(cadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {prioriade1D1, prioriade1D2, prioriade1D3, prioriade2D1, prioriade2D2, prioriade2D3, prioriade3D1, prioriade3D2, prioriade3D3});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel4, jLabel5, jLabel6});

        jScrollPane2.setViewportView(jPanel1);

        add(jScrollPane2, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // Ação da caixa de texto nome 
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void cadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarActionPerformed
        // Ação do botão cadastrar
      try{
          if(!jTextField1.getText().equals("")){
          professores.addProfessor(new Professor(jTextField1.getText(), 
                                        professores.getAddCont(), 
                                        disciplinas.getDisciplinas().get(prioriade1D1.getSelectedIndex()),
                                        disciplinas.getDisciplinas().get(prioriade1D2.getSelectedIndex()), 
                                        disciplinas.getDisciplinas().get(prioriade1D3.getSelectedIndex()), 
                                        disciplinas.getDisciplinas().get(prioriade2D1.getSelectedIndex()), 
                                        disciplinas.getDisciplinas().get(prioriade2D2.getSelectedIndex()), 
                                        disciplinas.getDisciplinas().get(prioriade2D3.getSelectedIndex()), 
                                        disciplinas.getDisciplinas().get(prioriade3D1.getSelectedIndex()),
                                        disciplinas.getDisciplinas().get(prioriade3D2.getSelectedIndex()),
                                        disciplinas.getDisciplinas().get(prioriade3D3.getSelectedIndex())
                                        ));
       j.inicializarProfessoresComAfinidades();   
       javax.swing.JOptionPane.showMessageDialog(null, professores.professores.get(professores.professores.size()-1));         
         }else javax.swing.JOptionPane.showMessageDialog(null, "Digite o nome do Professor.", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
      catch(IndexOutOfBoundsException indexOutOfBoundsException){
          javax.swing.JOptionPane.showMessageDialog(null, "Cadastre uma disciplina primeiro", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
      catch(NullPointerException NullPointerException){
          javax.swing.JOptionPane.showMessageDialog(null, "Bug ao carregar as disciplinas\nContacte o desenvolvedor", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
    }//GEN-LAST:event_cadastrarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cadastrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JComboBox prioriade1D1;
    private javax.swing.JComboBox prioriade1D2;
    private javax.swing.JComboBox prioriade1D3;
    private javax.swing.JComboBox prioriade2D1;
    private javax.swing.JComboBox prioriade2D2;
    private javax.swing.JComboBox prioriade2D3;
    private javax.swing.JComboBox prioriade3D1;
    private javax.swing.JComboBox prioriade3D2;
    private javax.swing.JComboBox prioriade3D3;
    // End of variables declaration//GEN-END:variables
    Professores professores;
}
